package com.sptpc.learspring.model;

import lombok.*;
import org.hibernate.annotations.Type;
import org.joda.money.Money;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

@Entity
@Table(name = "t_drink")
//@Data
//@ToString(callSuper = true)
@Getter
@Setter
//@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Drink extends BaseEntity implements Serializable {

    @ManyToOne
    private Category category;
    private String name;
//    org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyMinorAmount
    @Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyMinorAmount",
            parameters = {@org.hibernate.annotations.Parameter(name = "currencyCode",value = "CNY")} )
    private Money price;

    //no session死循环问题 需在本地配置里开启session解决方案
//    @ManyToMany
//    @JoinTable(name = "t_order_drink", joinColumns = {@JoinColumn(name = "items_id")})
//    private List<Order> drinkOrder;

    @Override
    public String toString() {
        return "Drink{" +
                "id=" + super.getId() +
                ", name='" + name + '\'' +
                ", price=" + price +
                ", category='" + category.getName() + '\'' +
                "} " ;
    }
}